<template>
  <div id="operateTopSearch">
    <div class="search-box">
      <el-form
        :inline="true"
        ref="operateForm"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="活动时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <!-- 编号部分 -->
        <el-form-item prop="searchContent">
          <el-input
            clearable
            v-model="formInline.searchContent"
            placeholder="活动名称、编号"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="活动状态" prop="state">
          <el-select v-model="formInline.state" clearable placeholder="全部">
            <el-option
              :label="item.dictLabel"
              :value="item.dictValue"
              v-for="item in activeStatusList"
              :key="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="二审状态" prop="twoAuditingState">
          <el-select
            v-model="formInline.twoAuditingState"
            clearable
            placeholder="全部"
          >
            <el-option
              :label="item.dictLabel"
              :value="item.dictValue"
              v-for="item in secondStatusList"
              :key="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动类型" prop="activityType">
          <el-select
            clearable
            v-model="formInline.activityType"
            placeholder="全部"
            class="activityType"
          >
            <el-option
              :label="item.dictLabel"
              :value="item.dictValue"
              v-for="item in activeTypeList"
              :key="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch"
            >搜索</el-button
          >
          <el-button type="success" plain @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'operateTopSearch',
  msg: '角色管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          state: '', // 活动状态,默认全部
          twoAuditingState: '', // 二审状态,默认全部
          activityType: '', // 活动类型,默认全部
          createTime: [], // 选择的时间
          searchContent: '', // 搜索框内容
          startTime: '',
          endTime: ''
        }
      }
    }
  },
  data() {
    return {
      // 活动状态列表
      activeStatusList: [{ dictLabel: '全部', dictValue: '' }],
      // 二审状态列表
      secondStatusList: [{ dictLabel: '全部', dictValue: '' }],
      // 活动类型状态列表
      activeTypeList: [{ dictLabel: '全部', dictValue: '' }]
    }
  },
  mounted() {
    this.getTopSearch()
  },
  methods: {
    // 获取顶部搜索条件
    async getTopSearch() {
      // 活动状态
      let activeStatusList = await sysNormalDisable('two_activity_status')
      this.activeStatusList = this.activeStatusList.concat(activeStatusList)
      // 二审状态
      let secondStatusList = await sysNormalDisable('activity_check_statu')
      this.secondStatusList = this.secondStatusList.concat(secondStatusList)
      // 活动类型
      let activeTypeList = await sysNormalDisable('activity_type', 'activeType')
      this.activeTypeList = this.activeTypeList.concat(activeTypeList)
      this.setDefaultValue()
      this.$emit('toSearch')
    },
    /* 搜索 */
    toSearch() {
      this.$emit('toSearch')
    },
    // 重置
    reset() {
      this.$refs['operateForm'].resetFields()
      this.setDefaultValue()
    },
    setDefaultValue() {
      this.formInline.state = this.activeStatusList[3].dictValue
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  }
}
</script>

<style lang="less">
#operateTopSearch {
  .search-box {
    padding-left: 30px !important;
  }
  .activityType {
    width: 90px;
  }
}
</style>
